package org.xqp.hrm.context;
import com.alibaba.fastjson.JSON;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.xqp.hrm.domain.Login;

/**
 * 这是一个工具类让我们从Security获取登录用户的信息
 */

public class LoginContext {

    public static Login getLogin(){
        try {
            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            String jsonUser = authentication.getPrincipal().toString();
            return JSON.parseObject(jsonUser,Login.class);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
